package Classroom;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketException;

public class UDPSend {
    public static void main(String[] args) throws Exception {
        //创建对象发送端
        DatagramSocket ds = new DatagramSocket();
        //创建数据
        String s ="我爱你";
        byte[] bytes = s.getBytes();
        InetAddress address = InetAddress.getByName("127.0.0.1");
        int port =10000;
        //调用对象发送数据
        DatagramPacket dp = new DatagramPacket(bytes, bytes.length,address,port);
        //发送
        ds.send(dp);
        //释放资源
        ds.close();
    }
}
